home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 10840 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.7 KB  |  55 lines

  1. Path: newsfeed.gsfc.nasa.gov!usenet
  2. From: MJA <monica@vlsi9.gsfc.nasa.gov>
  3. Newsgroups: comp.lang.c
  4. Subject: Loading linked structures from a file--what is standard way?
  5. Date: 20 Mar 1996 04:34:20 GMT
  6. Organization: NASA Goddard Space Flight Center -- Greenbelt, Maryland USA
  7. Message-ID: <4io1sd$b6u@post.gsfc.nasa.gov>
  8. NNTP-Posting-Host: vlsi14.gsfc.nasa.gov
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 1.1N (X11; I; SunOS 4.1.3 sun4c)
  13. X-URL: news:comp.lang.c
  14.  
  15. Suppose this is my code:
  16.  
  17. struct HELL {
  18.          char A[];
  19.          char B[];
  20.          char C[];
  21.          int number;
  22.          struct HELL *next;
  23.            } Devil, *ptr;
  24.  
  25. loadstruct()
  26. { function loads a structure with data gotten from a configuration file }
  27.  
  28.  
  29. I have a structure called HELL with elements char A, B, C; and int number;.
  30. I also have a data file with groups of these elements' data delimited by a :
  31. and groups separated by a $
  32.  
  33.  
  34. hot:hotter:hottest:10:$
  35. spark:flame:fire:20:$
  36. murder1:murder2:murder3:30:$
  37.  
  38. Suppose I don't know how many records I have.  I will create a dynamically
  39. linked list.  I want to dynamically create, in this case 3 linked structures of
  40. type HELL.
  41. I want to malloc space for each new structure and I want *ptr to point to it.
  42. So, my question is do I pass the *ptr to my loadstruct() function or do I
  43. create a space for each structure (malloc) and pass the whole structure to my
  44. function loadstruct()?
  45.  
  46. If I pass the *ptr, I will of course update it with *ptr = ptr -> *next;
  47.  
  48. Is this the most efficient way of loading dynamically linked structures from a
  49. file?
  50.  
  51. note: I'm not worried about memory, I'm more worried about speed.
  52.  
  53. Thanks, Monica
  54.  
  55.